package com.example.user.implicitintent;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.net.Uri;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class NewDialer1 extends AppCompatActivity {
//使用隐式Intent不太安全，android8.0以上版本已不建议使用
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newdialer1);

        final EditText phoneNum=(EditText)findViewById(R.id.phoneNum);
        final Button button=(Button)findViewById(R.id.Button01);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String call = phoneNum.getText().toString();

               if (PhoneNumberUtils.isGlobalPhoneNumber(call)){
                   //Intent intent=new Intent(<Action>,<Data>);
                   /*Intent intent=new Intent(Intent.ACTION_CALL_BUTTON); //隐式Intent
                   intent.setData(Uri.parse("tell:/"+call));*/
                   Intent intent=new Intent(Intent.ACTION_CALL_BUTTON, Uri.parse("tel://"+call));
                   startActivity(intent);
                   //Toast.makeText(NewDialer1.this,call,Toast.LENGTH_LONG).show();  //显示获取的号码
               }else {
                   Toast.makeText(NewDialer1.this,R.string.notify_incorrect_phonenum,Toast.LENGTH_LONG).show();
               }

            }
        });
    }
}
